
var pow = [0];
for(var i=1; i<=9; i++) {
    pow[i] = Math.pow(i, 5);
}

var n = (function() {
    var limit = Math.pow(9,5);
    var n=1, limit, tmp=0;
    while(1){
        n = n*10;
        tmp = tmp + limit;
        print(n + "..." + tmp);
        if(n>tmp){
           return n;
        }
    }
})();

print(n);

var getCount = function(a) {
    var sum=0, tmp=a;
    while(1) {
        tmp1 = tmp%10;
        tmp = (tmp - tmp1)/10;
        sum = sum + pow[tmp1];
        if(tmp == 0) {
            //print(a + "===" + sum);
            return sum;
        }
    }
}

function pe30() {
    var sum=0;
    for(var i=2; i<n; i++) {
        var tmp=getCount(i)
        if(tmp == i) {
            print(i + "===" + tmp);
            sum += i;
        }
    }
    return sum;
}


print(pe30());
